﻿function register() {
    var userName = document.getElementById("userName");
    var email = document.getElementById("email");
    if (userName.value == null || userName.value == "") {
        alert("用户名不能为空！");
        return;
    }
    if (password.value == null || password.value == "") {
        alert("密码不能为空！");
        return;
    }
    if (email.value == null || email.value == "") {
        alert("邮箱不能为空！");
        return;
    }

    memberAdd(userName.value, password.value, email.value);
}

function memberAdd(userName, password, email) {
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "/WebService.aspx/Register",
        data: "{'userName':'" + userName + "','password':'" + password + "','email':'" + email +  "'}",
        dataType: 'json',
        success: function (result, textStatus) {
            eval("var member =" + result.d);
            alert(member.UserName + "," + member.Email);
        },
        error:function(err) {
             alert("err:" + err);
         }
    });
 }

function loadMember() {
    alert("aaa");
    var memberTable = document.getElementById("memberTable");
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "/WebService.aspx/GetMembers",
        data: "{}",
        dataType: 'json',
        success: function (result, textStatus) {
            alert(result.d);
            eval("var member =" + result.d);
            var memberTable = document.getElementById("memberTable");
            var row = memberTable.insertRow();
            row.insertCell().innerHTML = member[1].UserName;
            row.insertCell().innerHTML = member[1].Email;
            var row1 = memberTable.insertRow();
            row1.insertCell().innerHTML = member[2].UserName;
            row1.insertCell().innerHTML = member[2].Email;
        },
        error: function (err) {
            alert("err:" + err);
        }
    });
}

